﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using ERP_RORZE_DLL.Product.database;
using ERP_RORZE_DLL.Product.DAO;

namespace ERP_RORZE.Product.PartData
{
    public partial class ctrlOptionData : DevExpress.XtraEditors.XtraUserControl
    {
        ClsOptionDataTable obj = new ClsOptionDataTable();
        ClsPartDataDAO clspartDAO = new ClsPartDataDAO();
        DataTable dt;

        public ctrlOptionData()
        {
            InitializeComponent();
        }

        void Re_load(object sender, EventArgs e)
        {
            dt = clspartDAO.GetAllOptionData();
            dgvOptionData.DataSource = dt;
        }

        private void btnAdd_Click(object sender, EventArgs e)
        {
            Frm_OptionDataAdd frmAdd = new Frm_OptionDataAdd();
            frmAdd.Re_Load += new EventHandler(Re_load);
            frmAdd.Show();
        }

        private void btnEdit_Click(object sender, EventArgs e)
        {
            Frm_OptionDataEdit frmEdit = new Frm_OptionDataEdit();
            frmEdit.ID = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "ID").ToString();
            frmEdit.AondNote = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "AondNote").ToString();
            frmEdit.ClampTime = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "ClampTime").ToString();
            frmEdit.CLUpdateday = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "CLUpdateday").ToString();
            frmEdit.InputDate = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "InputDate").ToString();
            frmEdit.JigID = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "JigID").ToString();
            frmEdit.LastOption = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "LastOption").ToString();
            frmEdit.MachineID = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "MachineID").ToString();
            frmEdit.Memo = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Memo").ToString();
            frmEdit.Note = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Note").ToString();
            frmEdit.OptionID = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "OptionID").ToString();
            frmEdit.PartID = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "PartID").ToString();
            frmEdit.ProTime = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "ProTime").ToString();
            frmEdit.StaffID = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "StaffID").ToString();
            frmEdit.TechDate = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "TechDate").ToString();
            frmEdit.ToolQty = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "ToolQty").ToString();
            frmEdit.UpdateDay = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "UpdateDay").ToString();
            frmEdit.Re_Load += new EventHandler(Re_load);
            frmEdit.Show();
        }

        private void btnReload_Click(object sender, EventArgs e)
        {
            Re_load(sender, e);
        }

        private void dgvOptionData_Load(object sender, EventArgs e)
        {
            Re_load(sender, e);
        }

        private void btnDelete_Click(object sender, EventArgs e)
        {
            obj.ID = int.Parse(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "ID").ToString());
            clspartDAO.DeleteOptionData(obj);
            Re_load(sender, e);

        }

        private void btnRefresh_Click(object sender, EventArgs e)
        {
            Re_load(sender, e);
        }

        private void btnAddNew_Click(object sender, EventArgs e)
        {
            btnAdd_Click(sender, e);
        }

        private void btEdit_Click(object sender, EventArgs e)
        {
            btnEdit_Click(sender, e);
        }

        private void btDelete_Click(object sender, EventArgs e)
        {
            btnDelete_Click(sender, e);
        }
    }
}
